package baseTest;

import java.util.*;

public class groupAnagrams {
    public static void main(String[] args) {

    }

    public static List<List<String>> process(String[] strs){
        HashMap<String,List<String>> hashMap = new HashMap<>();
        for (String str: strs) {
            String sort = sort(str);
            if (hashMap.containsKey(sort)){
                hashMap.get(sort).add(sort);
            } else {
                List<String> list = new ArrayList<>();
                list.add(sort);
                hashMap.put(sort,list);
            }
        }
        Collection<List<String>> values = hashMap.values();
        return new ArrayList<>(values);
    }

    public static String sort(String str){
        char[] chars = str.toCharArray();
        Arrays.sort(chars);
        return new String(chars);
    }
}
